<html>
<head>
<title>Test SipJs</title>
</head>
<body>
    <video id="remoteVideo"></video>
    <video id="remoteAudio"></video>
    <video id="localVideo" muted="muted"></video>
<!--<script type="text/javascript">

var global = {};

global.RTCSessionDescription = window.webkitRTCPeerConnection;

</script>-->

<!--<script src="sip-0.10.0.js"></script>-->
<script src="adapter-latest.js"></script>
<script src="sip-0.10.0.js"></script>

<script type="text/javascript">
var config = {
  // Replace this IP address with your FreeSWITCH IP address
  uri: '1000@192.168.10.136',

  // Replace this IP address with your FreeSWITCH IP address
  // and replace the port with your FreeSWITCH ws port
  ws_servers: 'wss://voipssl.ecrab.cn:7443',

  // FreeSWITCH Default Username
  authorizationUser: '1000',

  // FreeSWITCH Default Password
  password: 'Aa1234',

  traceSip: true

};

// Create a Simple interface with a user named bob and a remote video element in the DOM
var simple = new SIP.WebRTC.Simple({
  media: {
    remote: {
      //video: document.getElementById('remoteVideo'),
      // This is necessary to do an audio/video call as opposed to just a video call
      audio: document.getElementById('remoteAudio')
    }
  },
  ua: {
    uri: '1000@192.168.10.136',
    wsServers: ['wss://voipssl.ecrab.cn:7443'],
    authorizationUser: '1000',
    password: 'Aa1234',
    registerExpires: 60,
    traceSip: true
  }
});

simple.on('ringing', function() {
	//alert('ringing');
	simple.answer();
})

simple.call('1000');

/*
var ua = new SIP.UA(config);

ua.on('invite', function(session) {

var remoteVideo = document.getElementById('remoteVideo');
var localVideo = document.getElementById('localVideo');

session.on('trackAdded', function() {
  // We need to check the peer connection to determine which track was added

  var pc = session.sessionDescriptionHandler.peerConnection;

  // Gets remote tracks
  var remoteStream = new MediaStream();
  pc.getReceivers().forEach(function(receiver) {
    remoteStream.addTrack(receiver.track);
  });
  remoteVideo.srcObject = remoteStream;
  remoteVideo.play();

  // Gets local tracks
  var localStream = new MediaStream();
  pc.getSenders().forEach(function(sender) {
    localStream.addTrack(sender.track);
  });
  localVideo.srcObject = localStream;
  localVideo.play();
});
    var options = {
      media: {
        constraints: {
          audio: true,
          video: false
        }
      }
    };
session.accept(options);
});
*/
</script>
</body>
</html>
